package com.chongqing.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * create by yongli on 2021-06-27 21:46
 */
@Configuration
public class ServiceConfig {

    @Autowired
    private RestTemplateBuilder restTemplateBuilder;

    /**
     * 加上该注解，才能识别服务名，否则就只是普通的http
     *
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return restTemplateBuilder.build();
    }
}
